home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / vla / wcimit / cmpsub.asm next >
Assembly Source File  |  1993-06-03  |  4KB  |  164 lines

  1.     DOSSEG
  2.     .286
  3.     .MODEL SMALL
  4.     .CODE
  5.  
  6.     ASSUME cs:@code, ds:@code
  7.  
  8. ;====- DATA -=====
  9. ;
  10. ;upon entry:    Decompressit => loads .CMP image and decompresses it...
  11. ;
  12. ;*  DS:DX = pointer to filename
  13. ;*  AX != 0, image fitted to AX wide window
  14. ;*  AX == 0, image decompressed using [Xsize] for width
  15. ;*  [FileSeg] and [Destination] must both have valid segmnet values
  16. ;
  17. ;upon EXIT:
  18. ;
  19. ;*  AX=0 if no error, 1 means error
  20. ;*  Stuff in [FileSeg] is destoryed
  21. ;*  Decompressed image is in [Destination] segment
  22. ;*  Palette is at CmpPal
  23. ;
  24.  
  25.     GLOBAL  DeCompressIt:NEAR
  26.     GLOBAL  FileSeg:WORD, Destination:WORD, CmpPal:BYTE
  27.     
  28.     FileSeg     dw      0
  29.     Destination dw      0
  30.  
  31.     CmpPal  db      0,767 dup (0)
  32.  
  33.     Xsize       dw  0
  34.     Ysize       dw  0
  35.     Repeatcode  db  0
  36.     ScreenWidth dw  320
  37.         
  38.     SegMsg      db  "FATAL! You forgot to load [FileSeg] and/or [Destination]!!$"
  39.     FileMsg     db  "FATAL! File was not openable! (Probably not found.)$"
  40.  
  41. ;========- SubRoutines -========
  42.  
  43. DeCompressit proc near
  44.         pusha
  45.         push    ds es
  46.  
  47.         cmp     cs:[FileSeg],0
  48.         je      SegError
  49.         cmp     cs:[Destination],0
  50.         je      SegError
  51.  
  52.         push    ax
  53.  
  54.         mov     ax,cs
  55.         mov     es,ax  
  56.         mov     ax,3d00h        ;open file
  57.         int     21h
  58.         jnc     Noabort
  59.  
  60.         pop     ax
  61.  
  62.         popa
  63.         mov     ax,1        ;1 means file error
  64.         ret
  65. SegError:
  66.         mov     ax,cs
  67.         mov     ds,ax
  68.         mov     ah,9
  69.         mov     dx,offset SegMsg
  70.         int     21h
  71.         popa
  72.         mov     ax,2        ;2 means segment error
  73.         ret
  74. Noabort:
  75.         mov     bx,ax
  76.  
  77.         mov     ax,cs:[FileSeg]
  78.         mov     ds,ax
  79.         mov     ax,cs:[Destination]
  80.         mov     es,ax
  81.  
  82.         mov     cx,0ffffh               ;read whole file ( if < 64k )
  83.         xor     dx,dx    
  84.         mov     ah,3fh               
  85.         int     21h                
  86.         
  87.         mov     ah,3eh                  ;close source file 
  88.         int     21h                     
  89.  
  90.         mov     al,ds:[3]               ;read 4th byte (offset 3)
  91.         mov     cs:[repeatcode],al
  92.         mov     ax,ds:[4]               ;xsize
  93.         mov     cs:[xsize],ax
  94.         mov     ax,ds:[6]
  95.         mov     cs:[ysize],ax
  96.  
  97.         pop     ax              ;from push up top
  98.         mov     cs:[ScreenWidth],ax
  99.         or      ax,ax
  100.         jne     WidthAx         ;see if we use AX or Xsize
  101.  
  102.         mov     ax,cs:[Xsize]   ;use Xsize
  103.         mov     cs:[ScreenWidth],ax
  104. WidthAX:
  105.         xor     di,di
  106.         mov     si,776
  107.                         
  108.         mov     cx,cs:[xsize]
  109.         mov     bx,cs:[ysize]
  110.         mov     dl,cs:[repeatcode]
  111.         push    di
  112. TryAgain:
  113.         lodsb
  114.         cmp     al,dl           ;is byte a repeatcode?
  115.         je      decodeloop      ;yup do decode loop
  116.         stosb                   ;nope, it's a pixel, store it
  117. jumphere:
  118.         dec     cx              ;are we done with this line?
  119.         jne     tryagain        ;no, do another
  120.         mov     cx,cs:[xsize]
  121.         pop     di
  122.         add     di,cs:[ScreenWidth]
  123.         push    di
  124.         dec     bx              ;are we done with height?
  125.         jne     tryagain        ;nope go on
  126.         jmp     alldone         ;Yup, exit out
  127.  
  128. DECODELOOP:
  129.         lodsw                   ;ah=# of times: al= byte to repeat
  130.         stosb
  131.         jmp     dcskip
  132. Bigloop:
  133.         stosb
  134.         dec     ah              ;are we done with this repeat sequence?
  135.         je      jumphere        ;yup, go back up top
  136. dcskip:
  137.         dec     cx              ;are we done with this line?
  138.         jne     Bigloop
  139.         mov     cx,cs:[xsize]
  140.         pop     di
  141.         add     di,cs:[ScreenWidth]
  142.         push    di
  143.         dec     bx              ;are we done with the picture?
  144.         jne     Bigloop         ;nope, keep going...
  145.         jmp     alldone         ;yup
  146. AllDone:
  147.         pop     di              ;pull garbage di off stack
  148.         
  149.         mov     ax,cs
  150.         mov     es,ax           ;copy palette to CmpPal
  151.         
  152.         mov     si,8
  153.         mov     di,offset CmpPal
  154.         mov     cx,768/2
  155.         rep     movsw
  156.         
  157.         pop     es ds
  158.         popa
  159.         mov     ax,0            ;operation was successful
  160.         ret
  161. DeCompressit endp
  162.  
  163.     end
  164.